/*
** my_errors.c for asm in /home/vanet_c//proj-kw/asm
** 
** Made by charles-edouard vanet
** Login   <vanet_c@epitech.net>
** 
** Started on  Sat Dec  8 20:34:34 2012 charles-edouard vanet
** Last update Sat Dec 15 17:49:51 2012 charles-edouard vanet
*/

#include	"../includes/asm.h"

void	aff_char_error(t_my_file **my_file, char *error)
{
  int	i;
  int	find;

  i = -1;
  find = 0;
  my_fd_putchar('\t', 2);
  while ((*my_file)->tab_instruction[++i])
    {
      if (i > 1 && (*my_file)->tab_instruction[i] != NULL)
	my_fd_putchar(',', 2);
      else if (i == 1)
	my_fd_putchar(' ', 2);
      if (my_strcmp((*my_file)->tab_instruction[i], error) == 0)
	{
	  my_stderror("\e[31m");
	  my_stderror((*my_file)->tab_instruction[i]);
	  my_stderror("\e[0m");
	}
      else
	my_stderror((*my_file)->tab_instruction[i]);
    }
  my_fd_putchar('\n', 2);
}

void	check_instru_msg(t_list **list, int line, int type)
{
  my_fd_putchar('\t', 2);
  my_stderror((*list)->name);
  if (type == 1)
    {
      my_stderror(" : Unknown mnemonic line ");
    }
  if (type == 2)
    {
      my_stderror(" : Wrong parameter number line ");
    }
  my_put_nbr_error(line);
  my_stderror("\n\e[1mAssembling aborted on error.\e[0m\n");
  my_free_list(*list);
  exit(EXIT_FAILURE);

}

void		syntax_msg(t_list **list, t_my_file **my_file, char *error)
{
  my_fd_putchar('\t', 2);
  my_stderror((*list)->name);
  my_stderror(" : syntax error line ");
  my_put_nbr_error((*my_file)->line_nb);
  my_fd_putchar('\n', 2);
  if (error != '\0')
    aff_char_error(my_file, error);
  my_stderror("\e[1mAssembling aborted on error.\e[0m\n");
  my_free_list(*list);
  exit(EXIT_FAILURE);
}
